﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Quartz;
using iTelluro.Explorer.Infrastructure.CrossCutting.Logging;
using iTelluro.Explorer.Infrastructure.CrossCutting.NetFramework.Logging;
using SXMeteorological.Data.Utility;

namespace SXMeteorological.DataSyn.Temperature
{
    public class TemperatureJob:IJob
    {
        private readonly ILogger _logger;
        /// <summary>
        /// 构造函数
        /// </summary>
        public TemperatureJob()
        {
            _logger = LoggerFrameFactory.CreateLog();
           // _logger.LogInfo("执行气温任务构造函数");
        }


        public void Execute(IJobExecutionContext context)
        {
            HourTemperature();
            HourLowerestTemperature();
            HourToppestTemperature();
            Hour24TopTemperature();
            Hour24LowerTemperature();
        }

        private void HourTemperature()
        {
            try
            {
                string interfaceName = "getSurfEleInRegionByTime";
                string returnValue = "Lat,Lon,TEM";
                string featureName = "小时温度";
                string time = DateTime.UtcNow.ToString("yyyyMMddHH") + "0000";
                string dataCode = "SURF_CHN_MUL_HOR";
                string colorpath = AppDomain.CurrentDomain.BaseDirectory + @"color\Temperature.txt";
               // _logger.LogInfo(featureName + "**" + "小时温度图" + "***" + returnValue);
                CreateMap.CreateFeatureMap(interfaceName, returnValue, dataCode, featureName, "小时温度图", time, colorpath,"h");
            }
            catch (Exception ex)
            {
                _logger.LogError(string.Format("陕西省小时温度数据生成失败#{0}：{1}", DateTime.Now, ex.Message));
            }
        }
        /// <summary>
        /// 小时最低气温
        /// </summary>
        private void HourLowerestTemperature()
        {
            try
            {
                string interfaceName = "getSurfEleInRegionByTime";
                string returnValue = "Lat,Lon,TEM_Min";
                string featureName = "小时最低温度";
                string time = DateTime.UtcNow.ToString("yyyyMMddHH") + "0000";
                string dataCode = "SURF_CHN_MUL_HOR";
                string colorpath = AppDomain.CurrentDomain.BaseDirectory + @"color\Temperature.txt";
                //_logger.LogInfo(featureName + "**" + "小时最低温度图" + "***" + returnValue);
                CreateMap.CreateFeatureMap(interfaceName, returnValue, dataCode, featureName, "小时最低温度图", time, colorpath,"h");
            }
            catch (Exception ex)
            {
                _logger.LogError(string.Format("陕西省小时最低温度数据生成失败#{0}：{1}", DateTime.Now, ex.Message));
            }
        }
        /// <summary>
        /// 小时最高气温
        /// </summary>
        private void Hour24LowerTemperature()
        {
            try
            {
                string interfaceName = "getSurfEleInRegionByTime";
                string returnValue = "Lat,Lon,TEM_Max";
                string featureName = "小时最高温度";
                string time = DateTime.UtcNow.ToString("yyyyMMddHH") + "0000";
                string dataCode = "SURF_CHN_MUL_HOR";
                string colorpath = AppDomain.CurrentDomain.BaseDirectory + @"color\Temperature.txt";
               // _logger.LogInfo(featureName + "**" + "小时最高温度图" + "***" + returnValue);
                CreateMap.CreateFeatureMap(interfaceName, returnValue, dataCode, featureName, "小时最高温度图", time, colorpath,"h");
            }
            catch (Exception ex)
            {
                _logger.LogError(string.Format("陕西省小时最高温度数据生成失败#{0}：{1}", DateTime.Now, ex.Message));
            }
        }
        /// <summary>
        /// 过去24小时最高气温
        /// </summary>
        private void Hour24TopTemperature()
        {
            try
            {
                string interfaceName = "getSurfEleInRegionByTime";
                string returnValue = "Lat,Lon,TEM_Max_24h";
                string featureName = "过去24小时最高温度";
                string time = DateTime.UtcNow.ToString("yyyyMMddHH") + "0000";
                string dataCode = "SURF_CHN_MUL_HOR";
                string colorpath = AppDomain.CurrentDomain.BaseDirectory + @"color\Temperature.txt";
               // _logger.LogInfo(featureName + "**" + "过去24小时最高温度图" + "***" + returnValue);
                CreateMap.CreateFeatureMap(interfaceName, returnValue, dataCode, featureName, "过去24小时最高温度图", time, colorpath,"h");
            }
            catch (Exception ex)
            {
                _logger.LogError(string.Format("陕西省过去24小时最高温度数据生成失败#{0}：{1}", DateTime.Now, ex.Message));
            }
        }

        /// <summary>
        /// 过去24小时最低气温
        /// </summary>
        private void HourToppestTemperature()
        {
            try
            {
                string interfaceName = "getSurfEleInRegionByTime";
                string returnValue = "Lat,Lon,TEM_Min_24h";
                string featureName = "过去24小时最低温度";
                string time = DateTime.UtcNow.ToString("yyyyMMddHH") + "0000";
                string dataCode = "SURF_CHN_MUL_HOR";
                string colorpath = AppDomain.CurrentDomain.BaseDirectory + @"color\Temperature.txt";
               // _logger.LogInfo(featureName + "**" + "过去24小时最低温度图" + "***" + returnValue);
                CreateMap.CreateFeatureMap(interfaceName, returnValue, dataCode, featureName, "过去24小时最低温度图", time, colorpath,"h");
            }
            catch (Exception ex)
            {
                _logger.LogError(string.Format("陕西省过去24小时最低温度数据生成失败#{0}：{1}", DateTime.Now, ex.Message));
            }
        }
    }
}
